<%@page import="java.util.ArrayList"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="com.qububu.emporium.goodsType.dto.BigTypeDto"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>这是测试主页</title>

<style type="text/css">
#div{
	width: 800px; 
	background-color: lightGray; 
	text-align: center; 
	margin-top: 20px;
}

.div{
	width: 100px;
</style>
<script type="text/javascript" src="<%=request.getContextPath() %>/resource/js/jquery/jquery-1.8.2.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/resource/js/constants.js"></script>

<script type="text/javascript">

/* $(document).ready(function() { }*/

	// 通过大的类型超找小的类型及其对应商品
	$(function(){
		loadGoods();
		$(".testMenu").click(function() {
			$.ajax({
				/* trouble: post提交IE10传输数据错误 */
				type: 'post',
				/* type: 'get', */
				url: '../gtype/ajaxSearchGoodsLittleTypes',
				data: {
					'typeP' : this.id
				},
				dataType: 'json',
				success: function(obj) {
					if (obj.result == 1) {
						alert("出错了!!!  " + obj.message);
					} else {
						/* alert("--pid--"+ obj.typePid); */
						// 获取父节点ID
						$.each(obj.littleTypes, function(index, elem) {
							/* alert("index-" +index);
							alert(elem.typeId); */
							// 获取所有子类型数据信息
						} );
						$(obj.goodsList).each(function(index) {
							/* alert("index-" +index);
							alert(this.goodsId); */
							// 获取对应类型下所有商品
						} );
					}
				}
			});
			
		});
	});
	
	// 查找对应文章评论
	$(function(){
		$("#showA").click(function() {
			$.ajax({
				type: 'post',
				url: '../comment/ajaxSearchComment',
				data: {
					'goodsId' : '1'
				},
				dataType: 'json',
				success: function(obj) {
					if (obj.result != 0) {
						alert("出错了!!!" + obj.message);
					} else {
						$.each(obj.list, function(elem, index) {
							/* alert("index-" +index);
							alert(elem); */
							// 获取评论信息
						} );
					}
				}
			});
		});
	});

	// 删除文章
	$(function(){
		$("#showB").click(function() {
			$.ajax({
				type: 'post',
				url: '../article/ajaxDeleteArticle',
				data: {
					'articleId' : '31'
				},
				dataType: 'json',
				success: function(obj) {
					if (obj.result != 0) {
						alert("出错了!!!" + obj.message);
					} else {
						$.each(obj.list, function(elem, index) {
							/* alert("index-" +index);
							alert(elem); */
							// 获取评论信息
						} );
					}
				}
			});
		});
	});
	
	//添加评论
	$(function(){
		$("#testBu").click(function() {
			var context = $("#con").val();
			$.ajax({
				type: 'post',
				url: '../comment/addGoodsComment',
				data: {
					'goodsId' : '1',
					'msgContent' : context
				},
				dataType: 'json',
				success: function(res) {
					alert(res);
					if (res.result != 0) {
						alert("出错了!!!" + res.message);
					} else {
						alert(res.obj);
					}
				}
			});
		});
	});
	
	//添加对评论的回复
	$(function(){
		$("#testSubShow").click(function() {
			var content = $("#con1").val();
			$.ajax({
				type: 'post',
				url: '../comment/addGoodsComment',
				data: {
					'goodsId' : '1',
					'msgId' : '2',
					'msgContent' : content
				},
				dataType: 'json',
				success: function(res) {
					alert(res);
					if (res.result != 0) {
						alert("出错了!!!" + res.message);
					} else {
						alert(res.sub);
					}
				}
			});
		});
	});
	
	// 查找商品的type
	$(function(){
		$("#showType").click(function() {
			$.ajax({
				type: 'post',
				url: '../goods/ajaxSearchGoodsByType',
				data: {
					'typeP' : "1",
					'typeL' : '1'
				},
				dataType: 'json',
				success: function(obj) {
					if (obj.result != 0) {
						alert("出错了!!!" + obj.message);
					} else {
						$.each(obj.goodsList, function(elem, index) {
							/* alert("index-" +index);
							alert(elem); */
							// 获取评论信息
						} );
					}
				}
			});
		});
	});
	
	// 查找商品的所有信息
	$(function(){
		$("#showGoods").click(function() {
			$.ajax({
				type: 'post',
				url: '../goods/showGoodsInfo',
				data: {
					'goodsId' : "2"
				},
				dataType: 'json',
				success: function(obj) {
					if (obj.result != 0) {
						alert("出错了!!!" + obj.message);
					} else {
						alert(obj.goodsInfo.goodsId);
					}
				}
			});
		});
	});
	
	// 热词查找
	// 查找商品的所有信息
	$(function(){
		$("#hotSearch").click(function() {
			$.ajax({
				type: 'post',
				url: '../keySearch/ajaxHotSearch',
				dataType: 'json',
				success: function(obj) {
					if (obj.result != 0) {
						alert("出错了!!!" + obj.message);
					} else {
						alert(obj.hotWords.hotId);
					}
				}
			});
		});
	});
	
	// 测试登录
	$(function(){
		$("#loginBu").click(function() {
			var email = $("#email").val();
			var pwd = $("#pwd").val();
			$.ajax({
				type: 'get',
				url: '../user/ajaxLogin',
				data: {
					"email" : email,
					"password" : pwd
				},
				dataType: 'json',
				success: function(obj) {
					if (!(obj === '0') ) {
						alert("出错了!!!" + obj.message);
					}
				}
			});
		});
	});
	
</script>

<!-- 关于地图 -->
<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.1&key=8e224a5f1ea5161ede7d4d8da4f1cca0"></script>
<script type="text/javascript">

	var mapObj;
	var userDefaultPosition;
	var userPositionMarker;
	
	// 初始化地图
	
	function initMap() {
		
		userDefaultPosition = new AMap.LngLat(103.98757, 30.580274);
		
		mapObj = new AMap.Map("map_container", {
	    	level: 16, //地图初始化时的视野级别
	    	center: userDefaultPosition, //地图初始化时的中心点经纬度坐标
	    	zooms : [3,18], //地图视野级别范围，如：[3,19]，3 为最小级别，19 为最大级别
	    	dragEnable : true, //定义地图是否可以拖拽
	    	zoomEnable : true, //定义地图视野级别是否可以更改
	    	keyboardEnable : true, //定义地图是否可以被键盘控制
	    	jogEnable: true, //定义地图拖拽时是否支持缓动效果
	    	continuousZoomEnable: true, //定义地图是否有连续缩放效果
	    	doubleClickZoom : false, //定义地图是否可以双击放大
	    	scrollWheel: true, //定义地图是否支持鼠标滚轮缩放
	    	cursor: 'auto'//鼠标移上去以后显示为指针
	    });
		
		mapObj.bind(mapObj, 'dblclick', function(e) {
			
			// 考虑经过后台处理后提交给qububu.com
			window.location = 'http://cai.qububu.com/main/user/mainInfo';
		});
	}
	
	// 添加地图上的图标
	function createMeMarker() {
		
		var markerHtmlStr = '<div style="width: 40px; height: 40px;"><img src="../resource/images/common/map/marker_sprite.png" alt="目前实体店位置" /></div>';
		
		userPositionMarker = new AMap.Marker({
			id: 'userPositionMarker',
			cursor: 'auto',//鼠标移上去以后显示为指针
			position: userDefaultPosition,
			draggable: true,
			content: markerHtmlStr,
			offset:{x:-23,y:-46}  //偏移量需要根据marker内容大小来设置。无偏移量的情况，是从marker内容（图片）的左上角原点算起。所以一般偏移量是marker内容的-width/2和-height
		});
		
		mapObj.addOverlays(userPositionMarker);
	}
	
	$(document).ready(function() {
		initMap();
		
		createMeMarker();
	});

	
	function loadGoods(type) {
		if (type && type != null && "" != type) {
			type = 'MEAT_DIET';	
		}
		$.ajax({
			url: WEBROOT +'/goods/getGoods',
			type: 'post',
			dataType: 'json',
			data: {
				'goodsType': type, 
			},
			success : function(res) {
				if (res == 0) {
					var goods = res.goodsList;
					$.each(goods, function(i, good){
						alert(good.goodsName);
					});
				}
			}
		});
	}
</script>

</head>
<% 
/* List<BigTypeDto> bigTypeList = (List<BigTypeDto>) request.getAttribute("mainTypes"); */ 
List<BigTypeDto> bigTypeList = new ArrayList<BigTypeDto>();
%>
<body>
	<center>
		<h1>这里是商城</h1>
		<div style="height: 40px; line-height: 40px; width: 800px;">
			<a href="javascript:loadGoods('MEAT_DIET')">荤菜</a>
			<a href="javascript:loadGoods('VEGETABLE')">素菜</a>
			<a href="javascript:loadGoods('SOUP')">汤</a>
			<a href="javascript:loadGoods('SPECIALITY')">特产</a>
		</div>
		<!-- 测试登录 -->
		<hr/>
		<div style="width: 500px; height: 200px; background: #AED4F5; cursor: pointer;">
			邮箱<input type="text" id="email" />
			<br>
			密码<input type="text" id="pwd" />
			<br>
			<input type="button" id="loginBu" value="测试登录" />
		</div>
		
		<div id="map_container" title="点击进入做菜分享讨论" style="height: 400px; width: 600px; border: 1px solid #AED4F5;"></div>
		
		<%
		for (BigTypeDto bt : bigTypeList) {
		%>
		
		<div id="<%=bt.getTypeId() %>" class="testMenu" style="width: 280px; height: 40px; line-height: 40px; text-align: center; background: #AED4F5; border: 1px solid #FFFFFF; cursor: pointer;">
			<%=bt.getTypeName() %>
		</div>
		
		<%} %>
		<!-- 测试查询Type -->
		<hr/>
		<div style="width: 100px; height: 100px; background: #AED4F5; cursor: pointer;" id="showType">测试查询type</div>
		
		
		<!-- 测试查询商品评论 -->
		<hr/>
		<div style="width: 100px; height: 100px; background: #AED4F5; cursor: pointer;" id="showA">测试查询商品评论</div>
		
		<!-- 测试添加评论 -->
		<hr/>
		<div style="width: 400px; height: 100px;">
			<input type="text" id="con" />
			<input type="button" value="测试添加商品评论" id="testBu"/>
		</div>
		
		<!-- 测试删除文章 -->
		<hr/>
		<div style="width: 100px; height: 100px; background: #AED4F5; cursor: pointer;" id="showB">测试删除文章</div>
		
		<!-- 测试添加子评论 -->
		<hr/>
		<div style="width: 400px; height: 100px;">
			<input type="text" id="con1" />
			<input type="button" value="子评论测试添加" id="testSubShow"/>
		</div>
	
		<!-- 根据goodsId查看商品信息 -->
		<hr/>
		<div style="width: 100px; height: 100px; background: #AED4F5; cursor: pointer;" id="showGoods">测试查询商品信息</div>
			
		<!-- user信息修改 -->
		<hr />
		<div style="width: 400px; height: 100px;">
			<input type="text" id="conE" /><br>
			<input type="button" value="修改用户" id="testUserModify"/>
		</div>
		
		<!-- 热词查找，无参数 -->
		<hr/>
		<div style="width: 100px; height: 100px; background: #AED4F5; cursor: pointer;" id="hotSearch">热词查找，无参数</div>
		
		<div style="width: 100px; height: 100px;">
		
			<%
			/* session.setAttribute("user", "ZCW");
			session.setMaxInactiveInterval(5000);
		    ServletContext ContextA =session.getServletContext();
		    ContextA.setAttribute("session", session); */
		    session.setAttribute("user", "ZCW");
		    application.setAttribute("session", session);
			%>
			<a href="http://localhost:8080/test/testShareSession.jsp?sessionId=<%=session.getId() %>">测试session共用<%=session.getAttribute("user") %></a>
		</div>
		
		<div style="height: 100px; width: 500px; border: 1px solid blue;">
			<%-- <jsp:include page="<%=request.getContextPath() %>/testTwo/testMorePage"></jsp:include> --%>
			<%-- <c:import url="http://localhost:8080/qububu/testTwo/testMorePage" ></c:import> --%>
			<%
			String url = request.getScheme() + "://" + request.getHeader("host") + request.getContextPath();
			%>
			<c:import url="<%=url + \"/testTwo/testMorePage\" %>" ></c:import>
			
		</div>
		
	</center>
</body>
</html>